<template>
  <transition name="slideDown">
    <div class="modal" v-show="showModal">
      <div class="mask" v-show="showModal"></div>
      <div class="modal-diolog">
        <div class="header">
          <span>{{ title }}</span>
          <a href="javascript:void(0)" @click="$emit('cancel')">
            <div class="icon-close"></div>
          </a>
        </div>
        <div class="body">
          <slot name="body"></slot>
        </div>
        <div class="footer">
          <a
            href="javascript:;"
            class="btn"
            v-if="buttonType == 1"
            @click="$emit('close')"
            >{{ confirmText }}</a
          >
          <a
            href="javascript:;"
            class="btn"
            v-else-if="buttonType == 2"
            @click="$emit('cancel')"
            >{{ cancleText }}</a
          >
          <div class="btn-group" v-else-if="buttonType == 3">
            <a href="javascript:;" class="btn" @click="$emit('submit')">{{
              confirmText
            }}</a>
            <a
              href="javascript:;"
              class="btn btn-default"
              v-on:click="$emit('cancel')"
              >{{ cancleText }}</a
            >
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'modal',
  props: {
    modalType: {
      // 弹框类型： small middle hunge form
      type: String,
      default: 'form',
    },
    title: String, // 弹框标题

    buttonType: Number, //1 仅有确认按钮 2 取消按钮 3 确定取消
    confirmText: {
      type: String,
      default: '确认',
    },
    cancleText: {
      type: String,
      default: '取消',
    },
    showModal: Boolean,
  },
  methods: {},
}
</script>

<style lang="scss">
.modal {
  width: 100%;
  height: 100%;
  position: fixed;
  z-index: 31;
  top: 0;
  left: 0;
  transition: all 0.5s;

  &.slideDown-enter-active {
    top: 0;
    opacity: 1;
  }
  &.slideDown-leave-active {
    top: -100%;
    opacity: 0;
  }
  &.slideDown-enter,
  &.slideDown-leave-to {
    top: -100%;
    opacity: 0;
  }

  .mask {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
  }
  .modal-diolog {
    width: 660px;
    height: auto;
    padding: 20px;
    border-radius: 8px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    .header {
      height: 60px;
      font-size: 16px;
      .icon-close {
        position: absolute;
        top: 23px;
        right: 25px;
        width: 14px;
        height: 14px;
        background: url(/imgs/icon-close.png) no-repeat center;
        background-size: contain;
        transition: all 0.2s;
        &:hover {
          transform: rotate(360deg) scale(1.2);
        }
      }
    }
    .body {
      padding: 42px 40px 54px;
      font-size: 14px;
    }
    .footer {
      height: 82px;
      line-height: 82px;
      text-align: center;
      // background-color: #f5f5f5;
    }
  }
}
</style>
